/**
 * Goods 业务逻辑实现类
 * @author zhangq
 * @date 2015-1-8
 */
package com.chnbst.bstyun.service.impl;


import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.chnbst.bstyun.core.base.BaseService;
import com.chnbst.bstyun.core.common.helper.DaoHelper;
import com.chnbst.bstyun.model.pojo.Goods;
import com.chnbst.bstyun.model.vo.GoodsVo;
import com.chnbst.bstyun.service.GoodsService;

@Transactional
@Service
public class GoodsServiceImpl  extends BaseService implements GoodsService {

	//命名空间
	private final static String nameSpace = "com.chnbst.bstyun.mapper.GoodsMapper";

	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public boolean insertGoods(Goods goods) {
		return DaoHelper.insert(nameSpace, "insertGoods", goods);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
	@Override
	public boolean updateGoods(Goods goods) {
		return DaoHelper.update(nameSpace, "updateGoods", goods);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public int selectGoodsCount(Map<String, Object> map) {
		return DaoHelper.count(nameSpace, "selectGoodsCount", map);
	}

	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<GoodsVo> selectGoods(Map<String, Object> map) {
		return (List<GoodsVo>)DaoHelper.list(nameSpace, "selectGoodsVo", map);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public GoodsVo selectByGoodsId(String goodsId) {
		return  (GoodsVo) DaoHelper.query(nameSpace, "selectByGoodsId", goodsId);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public Goods selectByCondition(Map<String, Object> map) {
		return  (Goods)DaoHelper.query(nameSpace, "selectByCondition", map);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public GoodsVo selectGoodsVoByGoodsId(String goodsId) {
		return (GoodsVo)DaoHelper.query(nameSpace, "selectGoodsVoByGoodsId", goodsId);
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<Goods> selectAllGoods(Map<String, Object> map) {
		return (List<Goods>)DaoHelper.list(nameSpace, "selectAllGoods", map);
	}
	
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public Goods selectGoodsById(Integer id) {
		return (Goods)DaoHelper.query(nameSpace, "selectGoodsById", id);
	}
	
	//===================================以下为前台商城所需============================================//
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<GoodsVo> selectGoodsVoByTypeId(Map<String, Object> map) {
		return (List<GoodsVo>)DaoHelper.list(nameSpace, "selectGoodsVoByTypeId", map);
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<GoodsVo> selectNewGoodsVo(Map<String, Object> map) {
		return (List<GoodsVo>)DaoHelper.list(nameSpace, "selectNewGoodsVo", map);
	}
	
	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<GoodsVo> selectGoodsByTypeId(String typeId) {
		return (List<GoodsVo>) DaoHelper.list(nameSpace, "selectGoodsByTypeId", typeId);
	}

	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public int selectCountByTypeId(String typeId) {
		return  DaoHelper.count(nameSpace, "selectCountByTypeId", typeId);
	}

	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<Goods> selectGoodsByTId(String typeId) {
		return (List<Goods>) DaoHelper.list(nameSpace, "selectGoodsByTId", typeId);
	}

	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<Goods> selectGoodsByFeeId(String goodsFeeId) {
		return (List<Goods>) DaoHelper.list(nameSpace, "selectGoodsByFeeId", goodsFeeId);
	}

	@SuppressWarnings("unchecked")
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@Override
	public List<GoodsVo> selectGoodsByIndexModule() {
		return (List<GoodsVo>) DaoHelper.list(nameSpace, "selectGoodsByIndexModule", null);
	}
}
